package com.h.Strategy;

import com.h.autoconfigure.NettyConfigProperties;
import com.h.util.NetUtil;
import io.netty.bootstrap.AbstractBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @description:
 * @author     : Jager
 * @date       : 2024/4/23 14:18
 */
public class WebsocketClientStrategy implements BootstrapStrategy<Bootstrap, Channel> {
    @Override
    public AbstractBootstrap<Bootstrap, Channel> createBootstrap(NettyConfigProperties.Configuration config, ChannelHandler ch) throws Exception {
        final NioEventLoopGroup group = new NioEventLoopGroup();
        final Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(group)
                .channel(NioSocketChannel.class)
                .remoteAddress(NetUtil.getInetSocketAddress(config.getRemoteAddress()))
                .option(ChannelOption.TCP_NODELAY,true)
                .option(ChannelOption.SO_KEEPALIVE,true)
                .handler(ch);
        return bootstrap;
    }
}
